package cn.stevenyang.services;

import cn.stevenyang.signals.ConditionalSignal;
import cn.stevenyang.signals.CounterSignal;

public class SignalService {

    public enum Action {
        STOP_PROPAGATION, CONTINUE_PROPAGATION, DO_NOTHING
    }

    public Action checkTicket(Object signal, String currentWrap) {
        Action result = Action.DO_NOTHING;
        if (signal instanceof CounterSignal) {
            if (((CounterSignal) signal).getName().equals("break")) {
                ((CounterSignal) signal).decrement();
                result = ((CounterSignal) signal).isCountOver() ? Action.STOP_PROPAGATION : Action.CONTINUE_PROPAGATION;
            } else if (((CounterSignal) signal).getName().equals("continue")) {
                ((CounterSignal) signal).decrement();
                result = ((CounterSignal) signal).isCountOver() ? Action.STOP_PROPAGATION : Action.CONTINUE_PROPAGATION;
            }
        } else if (signal instanceof ConditionalSignal) {
            if (((ConditionalSignal) signal).getStopCondition().equals(currentWrap)) {

            } else if (((ConditionalSignal) signal).getStopCondition().equals(currentWrap)) {

            }
        }
        return result;
    }
}
